<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet
	version="1.0"
	xmlns:php="http://php.net/xsl"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
		

	<xsl:template name="article-options" match="object[@type='article']">
		<xsl:param name="rating" select="property[@name='rating']/value" />
		<xsl:param name="userLogin" select="property[@name='user_login']/value" />
		<xsl:param name="allowVote" select="@vote-allow" />
		
		<div class="info-wrapper">
			<xsl:apply-templates select="document(concat('xmodule://system/getVoted/', $rating, ';', $allowVote, ';', @type-id, ';', @id, ';0'))/data/response/vote" mode="post-vote" />
			
			<div class="info">
				<div class="time">
					<xsl:choose>
						<xsl:when test="property[@name='draft']/value = '1' and property[@name='published']/value = '0'">
							<xsl:text>не публиковался</xsl:text>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="property[@name='pubdate']/value" />
						</xsl:otherwise>
					</xsl:choose>
				</div>
				
				<xsl:if test="@type = 'link'">
					<div class="link-uri">
						<a href="{$baseURI}/blogs/link/{@id}">
							<xsl:attribute name="title">
								<xsl:value-of select="concat (property[@name='link']/value, ' | Переходов: ', property[@name='clicks']/value)" />
							</xsl:attribute>
							<xsl:value-of select="php:functionString ('XSLTDotsString', property[@name='link']/value, 30)" />
						</a>
					</div>
				</xsl:if>
				
				<div class="user-link">
					<a href="{$baseURI}/user/{$userLogin}">
						<xsl:value-of select="$userLogin" />
					</a>
				</div>
				
				<xsl:if test="property[@name='draft']/value = '0' or property[@name='published']/value = '1'">
					<div class="comments">
						<a title="Комментарии" href="{$baseURI}/post/{@type}/{@id}#comments">
							<xsl:value-of select="property[@name='count_comments']/value" />
						</a>
					</div>
				</xsl:if>
				
				<xsl:if test="@editable = '1'">
					<div class="controls">
						<a title="Редактировать" href="{$baseURI}/blogs/edit/{@type}/{@id}">
							<img src="{$baseURI}/images/settings-icon.png" align="top" alt="Редактировать" />
						</a>
					</div>
				</xsl:if>
			</div>
		</div>
	</xsl:template>
	
	<!-- POST VOTE -->
	<xsl:template match="vote" mode="post-vote">
		<xsl:param name="postId" select="object_id" />
		<xsl:param name="vote" select="mark" />
		<xsl:param name="allow" select="allow" />
		<xsl:param name="typeId" select="type_id" />
		<xsl:param name="rating" select="rating" />
		<xsl:param name="format" select="format" />
		
		<div class="vote-rating" id="post_rating_{$typeId}_{$postId}">
			<a class="minus" title="не нравится" href="#">
				<xsl:choose>
					<xsl:when test="$allow = 0 and $vote = ''">
						<xsl:attribute name="onclick">new Error ('Вы не можете проголосовать'); return false;</xsl:attribute>
						<xsl:attribute name="class">minus cant</xsl:attribute>
					</xsl:when>
					<xsl:when test="$allow = 0 and $vote != ''">
						<xsl:attribute name="onclick">new Error ('Повторное голосование запрещено'); return false;</xsl:attribute>
						<xsl:if test="$vote = 0">
							<xsl:attribute name="class">minus voted</xsl:attribute>
						</xsl:if>
						<xsl:if test="$vote != 0">
							<xsl:attribute name="class">minus cant</xsl:attribute>
						</xsl:if>
					</xsl:when>
					<xsl:otherwise>
						<xsl:attribute name="onclick">
							<xsl:value-of select="concat ('Post.vote (', $postId, ', ', $typeId, ', 0); return false;')" />
						</xsl:attribute>
					</xsl:otherwise>
				</xsl:choose>
				
				<img src="{$baseURI}/images/post-vote-minus.png" alt="Минус" />
			</a>
			
			<div class="number">
				<xsl:if test="number ($rating) &gt; 0">
					<xsl:attribute name="class">number plus</xsl:attribute>
				</xsl:if>
				<xsl:if test="number ($rating) &lt; 0">
					<xsl:attribute name="class">number minus</xsl:attribute>
				</xsl:if>
				<xsl:value-of select="$format" />
			</div>
			
			<a class="plus" title="нравится" href="#">
				<xsl:choose>
					<xsl:when test="$allow = 0 and $vote = ''">
						<xsl:attribute name="onclick">new Error ('Вы не можете проголосовать'); return false;</xsl:attribute>
						<xsl:attribute name="class">plus cant</xsl:attribute>
					</xsl:when>
					<xsl:when test="$allow = 0 and $vote != ''">
						<xsl:attribute name="onclick">new Error ('Повторное голосование запрещено'); return false;</xsl:attribute>
						<xsl:if test="$vote = 1">
							<xsl:attribute name="class">plus voted</xsl:attribute>
						</xsl:if>
						<xsl:if test="$vote != 1">
							<xsl:attribute name="class">plus cant</xsl:attribute>
						</xsl:if>
					</xsl:when>
					<xsl:otherwise>
						<xsl:attribute name="onclick">
							<xsl:value-of select="concat ('Post.vote (', $postId, ', ', $typeId, ', 1); return false;')" />
						</xsl:attribute>
					</xsl:otherwise>
				</xsl:choose>
				
				<img src="{$baseURI}/images/post-vote-plus.png" alt="Плюс" />
			</a>
		</div>
	</xsl:template>
	
</xsl:stylesheet>